package LeetCode;

public class LC_342_PowerofFour {

    public static void main(String[] args) {

    }

    static class Solution {
        public boolean isPowerOfFour(int num) {
            while (num > 0) {
                if (num == 1)
                    return true;
                if (num % 4 != 0)
                    return false;
                else
                    num = num / 4;
            }
            return false;
        }
    }

    static class Solution_2 {
        public boolean isPowerOfFour(int num) {
            int count0 = 0;
            int count1 = 0;
            while (num > 0) {
                if ((num & 1) == 1)
                    count1++;
                else
                    count0++;
                num >>= 1;
            }
            return count1 == 1 && (count0 % 2 == 0);
        }
    }

    static class Solution_3 {
        public boolean isPowerOfFour(int num) {
            if (num == 0) return false;
            int pow = (int) (Math.log(num) / Math.log(4));
            return num == Math.pow(4, pow);
        }
    }

}